package com.example.lvsuo.controller.cxg;


import com.example.lvsuo.entity.cxg.RecordFile;
import com.example.lvsuo.entity.cxg.vo.RecordFileVo;
import com.example.lvsuo.modal.Result;
import com.example.lvsuo.service.cxg.IRecordFileService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 文件记录表 前端控制器
 * </p>
 *
 * @author 心心念念
 * @since 2021-03-30
 */
@RestController
@RequestMapping("/recordFile")
public class RecordFileController {

    @Autowired
    IRecordFileService rs;

    @GetMapping
    Result queryRecordFile(){
        return Result.back(rs.list());
    }

    @GetMapping(params = {"getType=recordFile"})
    public Result queryRecordFilePlus(RecordFileVo recordFileVo){
        PageHelper.startPage(recordFileVo.getPageCur(),recordFileVo.getPageSize());
        PageInfo pageInfo = new PageInfo(rs.queryRecordFilePlus(recordFileVo));
return  Result.back("ok","20000",pageInfo) ;
    }

    @PostMapping
    public Result addRecordFile(@RequestBody RecordFile recordFile){
        System.out.println(recordFile);
        rs.save(recordFile);
        return Result.back("ok","20000");
    }

    @DeleteMapping("/{id}")
    public Result delRecordFile (@PathVariable String id){
        return Result.back("ok","20000",rs.removeById(id));
    }

    @GetMapping("/{id}")
    public Result getRecordFileByid (@PathVariable String id){
        RecordFile byId = rs.getById(id);
        return Result.back("ok","20000",byId);
    }

    @PutMapping
    public Result upRecordFileByid(@RequestBody RecordFile recordFile){
        rs.updateById(recordFile);
        return Result.back("ok","20000");
    }

}

